import sys

from PyQt5.QtWidgets import QApplication, QMainWindow, QMessageBox

from ErrorAnalyseWindow import ErrorAnalyseWindow
from DataPreProcessingWindows import DataPreProcessingWindow
from LooseCoupleWindow import LooseCoupleWindow
from PositionPlotWindow import PositionPlotWindow
from tplots import Tplots
from ui_launch import Ui_MainWindow

version = "1.0"


class LaunchWindow(QMainWindow, Ui_MainWindow):
    def __init__(self):
        super(LaunchWindow, self).__init__()
        self.setupUi(self)
        self.btnPositionPlot.clicked.connect(self.onbtnPositionPlotClicked)
        self.btnCloseAll.clicked.connect(self.onbtnCloseAllClicked)
        self.btnTplots.clicked.connect(self.onbtnTPlotsClicked)
        self.btnLooseCoop.clicked.connect(self.onbtnLooseCoupleClicked)
        self.btnErrorAnalyse.clicked.connect(self.onbtnErrorAnalyseClicked)
        self.btnGnssData.clicked.connect(self.onbtnGnssDataClicked)
        self.positionPlotWindow = PositionPlotWindow()
        self.dataPreProcessWindow = DataPreProcessingWindow()
        self.errorAnalyseWindow = ErrorAnalyseWindow()
        self.tplots = Tplots()
        self.looseCoupleWindow = LooseCoupleWindow()
        self.actionabout_qt.triggered.connect(self.about_qt)
        self.actionabout_gnss_tool.triggered.connect(self.about_tool)

    def onbtnLooseCoupleClicked(self):
        self.looseCoupleWindow.show()
        self.looseCoupleWindow.raise_()

    def onbtnGnssDataClicked(self):
        self.dataPreProcessWindow.show()
        self.dataPreProcessWindow.raise_()

    def onbtnErrorAnalyseClicked(self):
        self.errorAnalyseWindow.show()
        self.errorAnalyseWindow.raise_()

    def onbtnPositionPlotClicked(self):
        self.positionPlotWindow.show()
        self.positionPlotWindow.raise_()

    def onbtnTPlotsClicked(self):
        self.tplots.show()
        self.tplots.raise_()

    def onbtnCloseAllClicked(self):
        self.close()

    def closeEvent(self, a0) -> None:
        self.positionPlotWindow.close()
        self.looseCoupleWindow.close()
        self.dataPreProcessWindow.close()
        self.errorAnalyseWindow.close()
        self.tplots.close()

    def about_qt(self):
        QMessageBox.aboutQt(self, u'关于Qt')

    def about_tool(self):
        QMessageBox.about(self, 'About tplots',
                          '<p style="font-weight:bold; font-size:20pt;">'
                          'Gui tools for GNSS/INS'
                          '</p>'
                          '<body style="font-size:12pt;">'
                          '<p style="font-weight:bold">Version: 1.0</p>'
                          '<p>'
                          '<div style="font-weight:bold">Development:</div>'
                          '<div>'
                          'linfeng, linfeng_bao@outlook.com<br/>'
                          '</p>'
                          '</body>')


if __name__ == '__main__':
    app = QApplication(sys.argv)
    w = LaunchWindow()
    w.show()
    sys.exit(app.exec_())
